﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace WFcontrol.BL
{
    class quanlycaydm
    {
        accessdata con;
        Form frm;
        //SqlConnection sql = new SqlConnection();
        string sql;
        public quanlycaydm(WFcontrol.GUI.Frm_caydm f)
        {
        con = new accessdata();
            this.frm=f;
        }
        public void hienthi()
        {
            sql = "select * from danhmuc";
            con.Open();
            DataTable tb_dm = con.Get_DataTable(sql);
            TreeView tr = (TreeView)frm.Controls["treeView1"];
            foreach (DataRow dr in tb_dm.Rows)
            {
                TreeNode node = new TreeNode();
                node.Text = dr["TenDM"].ToString();
                node.Tag = dr["MaDM"].ToString();
                sql = "select * from ShopCD where MaDM='"+dr["MaDM"]+"'";
                DataTable shopcd = con.Get_DataTable(sql);
                foreach (DataRow row in shopcd.Rows)
                {
                    TreeNode node1 = new TreeNode();
                    node1.Text = row["TenLoai"].ToString();
                    node1.Tag = row["MaCD"].ToString();
                    node.Nodes.Add(node1);

                }
                tr.Nodes.Add(node);
            }
        }
        public void hienthilist_view(string MaDM)
        {
            sql = "select * from ShopCD where MaDM='"+MaDM+"'";
            con.Open();
            DataTable tblv = con.Get_DataTable(sql);
            con.Close();
            ListView lv = (ListView)frm.Controls["listView1"];
            lv.Items.Clear();
            foreach (DataRow row in tblv.Rows)
            {
                ListViewItem it = new ListViewItem();
                it.Text = row["TenLoai"].ToString();
                ListViewItem.ListViewSubItem it_sub = new ListViewItem.ListViewSubItem();
                it_sub.Text = row["MaCD"].ToString();
                it.SubItems.Add(it_sub);
                lv.Items.Add(it);

            }
        }
    }
}
